{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 《Python数据挖掘方法及应用》PyDm\n",
    "### 【第4章 多元数据的综合分析】数据与练习4 \n",
    "#### **（请在#下面问题的空白处写出代码并输出结果）**\n",
    "---"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "4.1 经济数据：收集2000－2010年共12年财政收入相关数据，分别是财政收入(y，百亿元)、国民生产总值(x1，百亿元)、税收(x2，百亿元)、进出口贸易总额(x3，百亿元)、经济活动人口(x4，百万人)。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#(1)试将这组数据输入电子表格。\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#(2)分别用Python 的read_csv()和read_excel()函数读取。\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#(3)试用Python函数获取2006—2011年的数据，以及2006—2011年的国民生产总值和经济活动人口数据。\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#(4)进行多元相关分析。\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#(5)进行多元回归分析。\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "4.2  为了研究31个省、市、自治区2007年城镇居民生活消费的分布规律，根据调查资料做区域消费类型划分，指标名称如下。此例样品数n=31，变量个数p=8。数据来源于《2008中国统计年鉴》。\n",
    "\n",
    "    食品：人均食品支出(元/人)；\n",
    "    衣着：人均衣着商品支出(元/人)；\n",
    "    设备：人均家庭设备用品及服务支出(元/人)；\n",
    "    医疗：人均医疗保健支出(元/人)；\n",
    "    交通：人均交通和通信支出(元/人)；\n",
    "    教育：人均娱乐教育文化服务支出(元/人)；\n",
    "    居住：人均居住支出(元/人)；\n",
    "    杂项：人均杂项商品和服务支出(元/人)。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#(1)用综合评价法进行综合分析。\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#(2)用主成分分析法进行综合分析。\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#(3)用系统聚类分析法进行聚类。\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "4.3 USJudgeRatings数据集(来自PyDataset包)包含了律师对美国高等法院法官的评分。数据框包含43个观测和12个变量(我们只需后11个变量)。\n",
    "\n",
    "CONT为律师与法官的接触次数，INTG为(法官的)正直程度，DMNR为风度，DILG为勤勉度，CFMG为案例流程管理水平，DECI为决策效率，PREP为审理前的准备工作，FAMI为对法律的熟悉程度，ORAL为口头裁决的可靠度，WRIT为书面裁决的可靠度，PHYS为体能，RTEN为是否值得保留。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>CONT</th>\n",
       "      <th>INTG</th>\n",
       "      <th>DMNR</th>\n",
       "      <th>DILG</th>\n",
       "      <th>CFMG</th>\n",
       "      <th>DECI</th>\n",
       "      <th>PREP</th>\n",
       "      <th>FAMI</th>\n",
       "      <th>ORAL</th>\n",
       "      <th>WRIT</th>\n",
       "      <th>PHYS</th>\n",
       "      <th>RTEN</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>AARONSON,L.H.</td>\n",
       "      <td>5.7</td>\n",
       "      <td>7.9</td>\n",
       "      <td>7.7</td>\n",
       "      <td>7.3</td>\n",
       "      <td>7.1</td>\n",
       "      <td>7.4</td>\n",
       "      <td>7.1</td>\n",
       "      <td>7.1</td>\n",
       "      <td>7.1</td>\n",
       "      <td>7.0</td>\n",
       "      <td>8.3</td>\n",
       "      <td>7.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>ALEXANDER,J.M.</td>\n",
       "      <td>6.8</td>\n",
       "      <td>8.9</td>\n",
       "      <td>8.8</td>\n",
       "      <td>8.5</td>\n",
       "      <td>7.8</td>\n",
       "      <td>8.1</td>\n",
       "      <td>8.0</td>\n",
       "      <td>8.0</td>\n",
       "      <td>7.8</td>\n",
       "      <td>7.9</td>\n",
       "      <td>8.5</td>\n",
       "      <td>8.7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>ARMENTANO,A.J.</td>\n",
       "      <td>7.2</td>\n",
       "      <td>8.1</td>\n",
       "      <td>7.8</td>\n",
       "      <td>7.8</td>\n",
       "      <td>7.5</td>\n",
       "      <td>7.6</td>\n",
       "      <td>7.5</td>\n",
       "      <td>7.5</td>\n",
       "      <td>7.3</td>\n",
       "      <td>7.4</td>\n",
       "      <td>7.9</td>\n",
       "      <td>7.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>BERDON,R.I.</td>\n",
       "      <td>6.8</td>\n",
       "      <td>8.8</td>\n",
       "      <td>8.5</td>\n",
       "      <td>8.8</td>\n",
       "      <td>8.3</td>\n",
       "      <td>8.5</td>\n",
       "      <td>8.7</td>\n",
       "      <td>8.7</td>\n",
       "      <td>8.4</td>\n",
       "      <td>8.5</td>\n",
       "      <td>8.8</td>\n",
       "      <td>8.7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>BRACKEN,J.J.</td>\n",
       "      <td>7.3</td>\n",
       "      <td>6.4</td>\n",
       "      <td>4.3</td>\n",
       "      <td>6.5</td>\n",
       "      <td>6.0</td>\n",
       "      <td>6.2</td>\n",
       "      <td>5.7</td>\n",
       "      <td>5.7</td>\n",
       "      <td>5.1</td>\n",
       "      <td>5.3</td>\n",
       "      <td>5.5</td>\n",
       "      <td>4.8</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                CONT  INTG  DMNR  DILG  CFMG  DECI  PREP  FAMI  ORAL  WRIT  \\\n",
       "AARONSON,L.H.    5.7   7.9   7.7   7.3   7.1   7.4   7.1   7.1   7.1   7.0   \n",
       "ALEXANDER,J.M.   6.8   8.9   8.8   8.5   7.8   8.1   8.0   8.0   7.8   7.9   \n",
       "ARMENTANO,A.J.   7.2   8.1   7.8   7.8   7.5   7.6   7.5   7.5   7.3   7.4   \n",
       "BERDON,R.I.      6.8   8.8   8.5   8.8   8.3   8.5   8.7   8.7   8.4   8.5   \n",
       "BRACKEN,J.J.     7.3   6.4   4.3   6.5   6.0   6.2   5.7   5.7   5.1   5.3   \n",
       "\n",
       "                PHYS  RTEN  \n",
       "AARONSON,L.H.    8.3   7.8  \n",
       "ALEXANDER,J.M.   8.5   8.7  \n",
       "ARMENTANO,A.J.   7.9   7.8  \n",
       "BERDON,R.I.      8.8   8.7  \n",
       "BRACKEN,J.J.     5.5   4.8  "
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from pydataset import data \n",
    "USJudgeRatings = data('USJudgeRatings')\n",
    "USJudgeRatings.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#(1)用综合评价法进行综合分析。\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#(2)用主成分分析法进行综合分析。\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#(3)用系统聚类分析法进行聚类。\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "4.4 UScereal数据集(来自PyDataset包)给出谷物营养的数据。变量mfr为生产厂家名，calories、protein、fat、sodium、fibre、carbo、sugars均为谷物的营养成分。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>mfr</th>\n",
       "      <th>calories</th>\n",
       "      <th>protein</th>\n",
       "      <th>fat</th>\n",
       "      <th>sodium</th>\n",
       "      <th>fibre</th>\n",
       "      <th>carbo</th>\n",
       "      <th>sugars</th>\n",
       "      <th>shelf</th>\n",
       "      <th>potassium</th>\n",
       "      <th>vitamins</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>100% Bran</td>\n",
       "      <td>N</td>\n",
       "      <td>212.12121</td>\n",
       "      <td>12.121212</td>\n",
       "      <td>3.030303</td>\n",
       "      <td>393.93939</td>\n",
       "      <td>30.303030</td>\n",
       "      <td>15.15152</td>\n",
       "      <td>18.181818</td>\n",
       "      <td>3</td>\n",
       "      <td>848.48485</td>\n",
       "      <td>enriched</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>All-Bran</td>\n",
       "      <td>K</td>\n",
       "      <td>212.12121</td>\n",
       "      <td>12.121212</td>\n",
       "      <td>3.030303</td>\n",
       "      <td>787.87879</td>\n",
       "      <td>27.272727</td>\n",
       "      <td>21.21212</td>\n",
       "      <td>15.151515</td>\n",
       "      <td>3</td>\n",
       "      <td>969.69697</td>\n",
       "      <td>enriched</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>All-Bran with Extra Fiber</td>\n",
       "      <td>K</td>\n",
       "      <td>100.00000</td>\n",
       "      <td>8.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>280.00000</td>\n",
       "      <td>28.000000</td>\n",
       "      <td>16.00000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>3</td>\n",
       "      <td>660.00000</td>\n",
       "      <td>enriched</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>Apple Cinnamon Cheerios</td>\n",
       "      <td>G</td>\n",
       "      <td>146.66667</td>\n",
       "      <td>2.666667</td>\n",
       "      <td>2.666667</td>\n",
       "      <td>240.00000</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>14.00000</td>\n",
       "      <td>13.333333</td>\n",
       "      <td>1</td>\n",
       "      <td>93.33333</td>\n",
       "      <td>enriched</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>Apple Jacks</td>\n",
       "      <td>K</td>\n",
       "      <td>110.00000</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>125.00000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>11.00000</td>\n",
       "      <td>14.000000</td>\n",
       "      <td>2</td>\n",
       "      <td>30.00000</td>\n",
       "      <td>enriched</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                          mfr   calories    protein       fat     sodium  \\\n",
       "100% Bran                   N  212.12121  12.121212  3.030303  393.93939   \n",
       "All-Bran                    K  212.12121  12.121212  3.030303  787.87879   \n",
       "All-Bran with Extra Fiber   K  100.00000   8.000000  0.000000  280.00000   \n",
       "Apple Cinnamon Cheerios     G  146.66667   2.666667  2.666667  240.00000   \n",
       "Apple Jacks                 K  110.00000   2.000000  0.000000  125.00000   \n",
       "\n",
       "                               fibre     carbo     sugars  shelf  potassium  \\\n",
       "100% Bran                  30.303030  15.15152  18.181818      3  848.48485   \n",
       "All-Bran                   27.272727  21.21212  15.151515      3  969.69697   \n",
       "All-Bran with Extra Fiber  28.000000  16.00000   0.000000      3  660.00000   \n",
       "Apple Cinnamon Cheerios     2.000000  14.00000  13.333333      1   93.33333   \n",
       "Apple Jacks                 1.000000  11.00000  14.000000      2   30.00000   \n",
       "\n",
       "                           vitamins  \n",
       "100% Bran                  enriched  \n",
       "All-Bran                   enriched  \n",
       "All-Bran with Extra Fiber  enriched  \n",
       "Apple Cinnamon Cheerios    enriched  \n",
       "Apple Jacks                enriched  "
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "UScereal = data('UScereal')\n",
    "UScereal.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#(1)用综合评价法进行综合分析。\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#(2)用主成分分析法进行综合分析。\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#(3)用系统聚类分析法进行聚类。\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
